package pluginFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

import pluginInterfaces.IPluginMetric;

/**
 * Class that is used to load and retrieve Metric plugins.
 * 
 * @author Andy Cullache
 */
public class MetricPluginFactory {

	/**
	 * Gets all the objects "IPluginMetric" found in the classpath. 
	 * For this you must first load the plugins from the "plugins / metric".
	 * @return      List of plugins found and charged to the classpath.
	 */
	public static List<IPluginMetric> retrieveAll() {
		List<IPluginMetric> iPluginList = new ArrayList<IPluginMetric>();
		try {
			if (PluginsCharger.Charger("plugins/metric"))
			{
				ServiceLoader<IPluginMetric> sl = ServiceLoader.load(IPluginMetric.class);
				sl.reload();
				for(IPluginMetric pl : sl)
				{
					iPluginList.add(pl);
				}
			}
		} catch (PluginFactoryException e) {
			e.printStackTrace();
		}
	    return iPluginList;
	}

}
